home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3 / CHAPTE19 / EX1.C < prev    next >
C/C++ Source or Header  |  1995-05-13  |  3KB  |  60 lines

  1. // ex1.c - Create key example.
  2.  
  3. #include <windows.h>
  4. #include <winreg.h>
  5. #include <genstub.c>
  6.  
  7. LRESULT FAR PASCAL WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  8. {
  9.     switch( uMsg )
  10.     {
  11.         case WM_COMMAND:    // process menu items
  12.             switch( wParam )
  13.             {
  14.                 case IDM_TEST:
  15.                 {
  16.                     HKEY  hKeyResult = 0;
  17.                     DWORD dwDisposition = 0;
  18.  
  19.                     // Create "MyDoc" shell interface.
  20.                     LONG  lResult = RegCreateKeyEx( HKEY_CLASSES_ROOT,
  21.                                                     "MyDoc\\shell\\&Test\\command",
  22.                                                     0, "", REG_OPTION_VOLATILE,
  23.                                                     KEY_ALL_ACCESS, NULL,
  24.                                                     &hKeyResult, &dwDisposition );
  25.                     // Program the registry to use Notepad to open the document.
  26.                     if ( lResult == ERROR_SUCCESS )
  27.                     {
  28.                        lResult = RegSetValueEx( hKeyResult, NULL, 0, REG_SZ,
  29.                                                 "NotePad %1",
  30.                                                 lstrlen( "NotePad %1" ) );
  31.                        RegCloseKey( hKeyResult );   // close MyDoc key.
  32.                     }
  33.                     // Create .MDC file extension connection.
  34.                     lResult = RegCreateKeyEx( HKEY_CLASSES_ROOT, ".MDC",
  35.                                               0, "", REG_OPTION_VOLATILE,
  36.                                               KEY_ALL_ACCESS, NULL,
  37.                                               &hKeyResult, &dwDisposition );
  38.                     // Connect .MDC with MyDoc type.
  39.                     if ( lResult == ERROR_SUCCESS )
  40.                     {
  41.                        // Set the value of the .MDC key to "MyDoc".
  42.                        lResult = RegSetValueEx( hKeyResult, NULL, 0, REG_SZ, "MyDoc",
  43.                                                 lstrlen( "MyDoc" ) );
  44.                        RegCloseKey( hKeyResult );
  45.                     }
  46.                 }
  47.                 break;
  48.                 case IDM_EXIT:
  49.                     DestroyWindow( hWnd );
  50.                     break;
  51.             }
  52.             break;
  53.         case WM_DESTROY:
  54.             PostQuitMessage( 0 );
  55.             break;
  56.         default:            // default windows message processing
  57.             return DefWindowProc( hWnd, uMsg, wParam, lParam );
  58.     }
  59.     return( 0L );
  60. }